In multi-threaded applications, it is common to find that a given thread of execution of the application corresponds to exactly one thread in the operating system. This is termed a 1-to-1 threading model. For applications requiring hundreds or thousands of threads, the overhead of switching between these threads can hinder performance as too much time is spent performing context switches. Context switch refers to an entity scheduling threads (presumably an operating system) having decided to switch from a currently running thread to another thread, which involves saving a CPU state associated with the current thread and loading a previously saved CPU state of the thread to be run next. Examples of information comprised by the CPU state include, but are not limited to, register values and status flags.
A common solution to the problem of overhead associated with context switches is to map M program threads onto N operating system threads. This type of threading model is referred to as an M-to-N threading model. In a M-to-N threading model, each native operating system thread actually contains M threads of execution from an application's standpoint. M-to-1 is a specific case of M-to-N, where N=1. By mapping M program threads onto N operating system threads, the overhead associated with switching between operating system threads is advantageously reduced.
Because each program thread is mapped to exactly 1 operating system thread in a 1-to-1 threading model, any exception encountered by a particular operating system thread will be contained by that particular program thread. However, in an M-to-N threading model (i.e., N<M), M program threads are being run on N operating system threads. Thus, when an exception occurs in an operating system thread, care must be taken to contain the exception in the associated program thread in which it occurred without affecting other program threads sharing the operating system thread for that particular program thread. Conventional approaches for converting 1-to-1 threading models to M-to-N threading models do not address the issue of exception handling in a manner that limits adverse effect of an exception in a program thread in which it occurs without affecting other program threads sharing an operating system thread for that particular program thread.
Therefore, an approach for facilitating handling of exceptions in a manner that overcomes adverse considerations associated with exception handling in M-to-N threading models would be useful, advantageous and novel.